<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialog" :before-close="handleClose"
             title="成绩分析" width="80%">
    <div class="app-container">
      <el-row>
        <el-col :span="12">
          <line-chart ref="line"></line-chart>
        </el-col>
        <el-col :span="12">
          <pie-chart ref="pie"></pie-chart>
        </el-col>
      </el-row>
    </div>
  </el-dialog>
</template>

<script>
  import service from '../../../utils/request'
  import eForm from './form'
  import LineChart from './LineChart'
  import PieChart from './PieChart'
  import count from '@/api/common/count'

  export default {
    components: {
      LineChart,
      PieChart
    },
    data() {
      return {
        dialog: false,
        loading: true,
        total: 0,
        isAdd: false,
        college: [],
        specialty: [],
        grade: [],
        sid: null,
        params: {
          cid: null
        },
        data: null
      }
    },
    methods: {
      load() {
        count.countCourseScore(this.params).then(res => {
          this.data = res;
          this.$refs.line.data = res;
          this.$refs.line.initChart();
          this.$refs.pie.data = res;
          this.$refs.pie.initChart();
        })
      },
      sizeChange(val) {
        this.params.limit = val
        this.load()
      },
      pageChange(val) {
        this.params.offset = val
        this.load()
      },
      toQuery() {
        this.load()
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            this.dialog = false
            done();
          })
          .catch(_ => {
          });
      },
      handleSelectionChange(val, row) {
        if (val.length == 0) {
          this.param.sid = null
        } else if (val.length > 1) {
          this.$refs.table.clearSelection()
          this.$refs.table.toggleRowSelection(row)
          val.splice(0, val.length - 1)
          this.param.sid = val[0].id
        } else {
          this.param.sid = val[0].id
        }
      },
      addScore(val) {
        this.$refs.form.dialog = true
        this.$refs.form.form["cid"] = this.params.cid
        this.$refs.form.form["sid"] = val.sid
      }
    }
  }
</script>

<style scoped>
  .status {
    color: green;
  }
</style>
